package hhm.android.library.datePicker.adapter.datetime;

import androidx.annotation.NonNull;

import java.util.Calendar;

import hhm.android.library.datePicker.bean.DateParams;
import hhm.android.library.datePicker.bean.DatePick;

public class MonthAdapter extends DatePickAdapter {

    public MonthAdapter(@NonNull DateParams dateParams, @NonNull DatePick datePick, int selectColor) {
        super(dateParams, datePick, selectColor);
    }

    @Override
    public int getCurrentIndex() {
        return mData.indexOf(mDatePick.month);
    }

    @Override
    public void refreshValues() {
        Calendar calendar = Calendar.getInstance();

        calendar.setTime(mDateParams.currentDate);
        int currentYear = calendar.get(Calendar.YEAR);
        if (mDatePick.year == currentYear) {
            int endMonth = calendar.get(Calendar.MONTH);
            setData(getArray(endMonth + 1));
        } else {
            setData(getArray(12));
        }
    }

    @Override
    public String getItem(int position) {
        int number = mData.get(position);
        return number + "月";
    }
}
